<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
    <link href="{$Think.config.RESOURCEURL}wx_assets/iconfont/iconfont.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
    <link type="text/css" rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/zepto.alert.css" />
    <link href="{$Think.config.RESOURCEURL}wx_assets/personCenter/css/index.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
    <script src="{$Think.config.RESOURCEURL}wx_assets/personCenter/js/mediaQuery.min.js{$Think.config.RESOURCE_VER}"></script>
    <script type='text/javascript' src='{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js'></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js" type="text/javascript"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}"></script>
    <link href="//at.alicdn.com/t/font_247327_bb93xb90dm5i2j4i.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/product/cookie.js{$Think.config.RESOURCE_VER}"></script>
</head>
<body id="change-password">
  <ul>
    <li>
      <i class="iconfont">&#xe6b2;</i>
      <input type="password" name="" value="" placeholder="请输入旧密码" class="old-password">
    </li>
    <li>
      <i class="iconfont">&#xe6b2;</i>
      <input type="password" name="" value="" placeholder="请输入设置新密码" class="new-password">
    </li>
    <li>
      <i class="iconfont">&#xe6b2;</i>
      <input type="password" name="" value="" placeholder="请输确认密码" class="confirm-password">
    </li>
  </ul>
  <div class="save-btn">保存</div>
<script>
  function Page() {};

  $.extend(Page.prototype, {
      init: function () {
          this.bindEvents();
          console.log($.util.getUa())
      },

      // 绑定事件
      bindEvents: function() {
          $('.save-btn').click($.proxy(this.handleSaveBtnClick, this));
      },

      // 点击保存按钮
      handleSaveBtnClick: function() {
        var oldPwd = $('.old-password').val();
        var newPwd = $('.new-password').val();
        var confirmPwd = $('.confirm-password').val();
        if (!oldPwd) {
          $.util.alert("请输入旧密码！");
          return false;
        }
        if (!newPwd) {
          $.util.alert("请输入新密码！");
          return false;
        } contextmenu=""
        if (!confirmPwd) {
          $.util.alert("请再次输入新密码！");
          return false;
        }
        if (confirmPwd !== newPwd) {
          $.util.alert("两次输入的密码不一致！");
          return false;
        }
        var params = {
          password: oldPwd,
          newPassword: newPwd
        }
        $.ajax({
            type: "get",
            url: '{$Think.config.SERVER_HOST}call.json?customerId={$customerId}',
            dataType: 'json',
            data: {
               token: getCookie('token'),
               module: 'personCenter',
               method: 'changePassword',
               params: JSON.stringify(params)
            },
            success: $.proxy(this.handleSaveSucc, this),
            error: $.proxy(this.handleSaveError, this)
        });
      },

      // 保存成功
      handleSaveSucc: function(res) {
        if (+res.code === 0) {
          $.util.alert(res.msg);
          history.back();
        } else {
          $.util.alert(res.msg);
        }
      },

      // ajax请求出错
      handleSaveError: function(err) {
        $.util.alert(err);
      }
  }) ;

  var page = new Page();
  page.init();
</script>
</body>
</html>
